package com.youlai.boot.system.controller;

import com.youlai.boot.common.result.Result;
import com.youlai.boot.common.result.ResultCode;
import com.youlai.boot.system.model.QB.Construct;
import com.youlai.boot.system.service.ConstructService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/v1/construct")
public class ConstructController {

    @Autowired
    private ConstructService constructService;

@PostMapping("/save")
    public Result<?> saveConstruct(@RequestBody Construct construct){
        return Result.judge(constructService.saveConstruct(construct),"添加成功","添加失败");
    }
    @PostMapping("/all")
    public Result<List<Construct>> getAllConstruct(){
    List<Construct> constructs = constructService.getAllConstruct();
    Result<List<Construct>> result;
    if (!constructs.isEmpty()){
        result = Result.success(constructs);
        result.setMessage("查询成功");
        result.setCode(ResultCode.SUCCESS.getCode());
    }
    else {
        result=Result.failed(ResultCode.SYSTEM_EXECUTION_ERROR);
        result.setMessage("查询失败");
    }
    return result;
    }
    @DeleteMapping("{id}")
    public  Result<?> deleteConstructById(@PathVariable Integer id ){
    return Result.judge(constructService.deleteConstructById(id),"删除成功","删除失败");
    }
}
